<template>
  <cube-page type="button-view" title="两票图片">
    <div slot="content">
      <div class="scroll-list-wrap zscrollWrap">
        <div class="zcardWrap">
          <div class="zcard" v-if="lst_orderPicture">
            <div class="zui-flex zcardRow">
              <div class="zlabel">品名</div>
              <div class="zdes">{{lst_orderPicture.name}}</div>
            </div>
            <div class="zui-flex zcardRow">
              <div class="zlabel">规格</div>
              <div class="zdes">{{lst_orderPicture.specifications}}</div>
            </div>
          </div>
        </div>
      </div>
      <div class="zwrap">
        <div class="imgs-container">
          <img :src="img" v-for="(img, index) in imgs" :key="index" @click="handleImgsClick(index)" class="zimg">
        </div>
      </div>

    </div>
  </cube-page>
</template>

<script>
import {
  mapState,
  mapGetters,
  mapMutations,
  mapActions
} from 'vuex'

import CubePage from '@/components/cube-page'
import {zOrderPicture} from '@/util/api';

export default {
  name: 'OrderPicture',
  components: {
    CubePage
  },
  computed: {
    ...mapState(['loginUserInfo']),
  },
  data () {
    return {
      showLoading: true,
      lst_orderPicture: null,
      imgs: [],
      curOrderId: ''
    }
  },
  created () {

  },
  mounted() {
    this.curOrderId = this.$route.params.id;
    let lst_orderPicture = this.zutil.lStorage.getParam('lst_orderPicture');
    if(lst_orderPicture){
      this.lst_orderPicture = JSON.parse(lst_orderPicture);
      console.log(this.lst_orderPicture)
      this.fetchList();
    }
  },
  watch: {

  },
  methods: {
    ...mapMutations(['setW_shortageData']),
    async fetchList () {
      let tbl_param = {
        curOrderId: this.lst_orderPicture.id
      }

      const zuiCubeLoading = this.$createToast({time: 0,txt: '正在加载中...'});
      zuiCubeLoading.show();
      let res = await zOrderPicture(tbl_param);
      res = this.zutil.formatAxiosData(res);
      zuiCubeLoading.hide();

      console.log(res)
      if(res.code == '0000'){
        if(res.data.list && res.data.list.length){
          res.data.list.forEach(v=>{
            if(v.imagedata.indexOf('data:image/png;base64,') == -1){
              v.imagedata = 'data:image/png;base64,'+v.imagedata;
            }
            this.imgs.push(v.imagedata);
          })
        }else{
          this.$createToast({type: 'error', time: 2000, txt:  "没有找到两票制图片！"}).show();
        }

      }else{
        this.$createToast({type: 'error', time: 2000, txt: res.message || "获取缺货信息列表失败！"}).show();
      }
    },
    handleImgsClick(index) {
      this.initialIndex = index
      const params = {
        $props: {
          imgs: this.imgs,
          initialIndex: 'initialIndex',
          loop: false
        },
        $events: {
          change: (i) => {
            this.initialIndex = i
          }
        }
      }
      this.$createImagePreview({ ...params }).show()
    }
  }
}
</script>

<style scoped lang="scss">

.fab-main-container {
  /deep/ {
    .fab-item-title {
      font-size: 14px;
      padding: 7px;
      background: #fc9153!important;
      color: #fff!important;
    }
  }
}
.zscrollWrap {
  height: auto;
  border: 0;
  .zcardWrap {
    .zcard {
      margin-bottom: 0;
    }
  }
}
.zwrap {
  border: 0;
  padding: 10px;
  .zimg {
    width: 100%;
    margin: 10px auto;
    border-radius: 10px;
    box-shadow: 0px 0px 10px rgba(0,0,0,0.2);

    &:first-child {
      margin-top: 0;
    }
  }
}
</style>
